<template>
    <div @touchmove="pagemove">
        <!-- 头部开始 -->
        <header id="header">
            <router-link to="/selectCity" class="toAddress">
                <!-- 公共数据部分 -->
                <span>{{this.$store.state.location}}</span>
                <i class="dropdown"></i>
            </router-link>
            <div class="search">
                <input type="text" v-model="search">
            </div>
            <router-link to="/login" class="man-icon">
                <img src="../assets/images/man.png" alt="">
            </router-link>
        </header>
        <!-- 头部 -->
        <div class="banner">
          <div class="banner_left">
            <img src="../assets/images/meituan.png" alt="">
            <div class="banner_message">
              <span>省钱利器 购物超划算</span>
              <span>吃喝玩乐尽在美团</span>
            </div>
          </div>
          <a href="javascript:;" class="banner_right">
            去APP
          </a>
        </div>
        <!-- 导航栏部分开始 -->
        <nav>
            <ul class="navbar">
                <li v-for="(item,index) in navbar" :key="index">
                    <router-link :to="item.link" class="toAddress">
                        <i class="item-icons"></i>
                        <span class="item-title">{{item.title}}</span>
                    </router-link>
                </li>
            </ul>
        </nav>
        <!-- 导航栏部分结束 -->
        <!-- 主体部分开始 -->
        <main>
            <!-- 猜你喜欢部分开始 -->
            <dl id="index" index="1">
                <dt>猜你喜欢</dt>
                <dd v-for="(item,index) in list" :key="index" class="guess">
                    <router-link to="/" class="item-commodity">
                        <div class="commodity-pic">
                            <img :src="item.src" alt="">
                        </div>
                        <div class="description">
                            <h5>{{item.name}}</h5>
                            <p>{{item.description}}</p>
                            <section>
                                <span class="actual-price"><i class="num-price">{{item.actualPrice}}</i>元</span>
                                <span class="market">门市价<span class="market-price">{{item.marketPrice}}</span>元</span>
                                <em class="sold">已售<i class="sold_num">{{item.sold}}</i></em>
                            </section>
                        </div>
                    </router-link>
                </dd>
            </dl>
            <!-- 猜你喜欢部分 -->
            <div class="checkAll">
                <div class="left-check">查看全部团购</div>
            </div>
        </main>
        <!-- 主体部分 -->
        <!-- 尾部导航栏开始 -->
        <footer>
            <div class="footer-navbar">
                <router-link to="/login" class="btn-login">
                    登录
                </router-link>
                <router-link to="/register" class="btn-reg">
                    注册
                </router-link>
            </div>
            <div class="footer-location">
                <span class="city">城市：</span>
                <img src="../assets/images/icon_address.png" alt="">
                <router-link to="/selectCity">
                    {{this.$store.state.location}}
                </router-link>
            </div>
        </footer>
        <!-- 尾部导航栏结束 -->
        <!-- 电梯导航开始 -->
        
        <a v-show="show" class="icon-elevator" href="#header"></a>
        
        <!-- 电梯导航 -->
    </div>
</template>
<script>
export default {
  data: function() {
    return {
      show:false,
      search: "请输入商家名、品类或者商圈...",
      navbar: [ //当前页面自己的数据
        {title:"美食",link:"/takeoutfood"},
        {title:"猫眼电影",link:"/takeoutfood"},
        {title:"酒店",link:"/takeoutfood"},
        {title:"休闲娱乐",link:"/takeoutfood"},
        {title:"外卖",link:"/takeoutfood"},
        {title:"KTV",link:"/takeoutfood"},
        {title:"周边游",link:"/takeoutfood"},
        {title:"丽人",link:"/takeoutfood"},
        {title:"小吃快餐",link:"/takeoutfood"},
        {title:"全部分类",link:"/takeoutfood"}
      ],
      list: []
    };
  },
  methods:{
    pagemove(){
      
      var page = $(window).scrollTop();
      if(page > $(".guess").eq(0).offset().top){
            this.show=true;
      }else{
            this.show=false;
      }
    }
  },
  mounted() {
    // this.$http.get('./data/data.json')
    // .then((res) => {
    //     this.msg = res.data.msg;
    // });
    // this.$store.commit('caddress',a)
    // 返回到上一级
    // this.$router.go(-1)
    // 可以指定跳转到某一个页面
    // this.$router.push('/movie')
    // 获取路由参数
    // this.$route.params.id
    // replace替换当前页面
    // this.$router.replace('/movie')

    // 精灵图的循环
    var icons = document.querySelectorAll(".item-icons");
    for (var i = 0; i < icons.length; i++) {
      if (i < 5) {
        icons[i].style.backgroundPosition = `-${4 + i * 83}px -4px`;
      } else {
        icons[i].style.backgroundPosition = `-${4 + (i - 5) * 83}px -85px`;
      }
    }
    if (this.$store.state.location == "鞍山") {
      this.$http.get("./data/anshan_data.json").then(res => {
        this.list = res.data.list;
      });
    }else if(this.$store.state.location == "沈阳"){
      this.$http.get("./data/shenyang_data.json").then(res => {
        this.list = res.data.list;
      });
    }else if(this.$store.state.location == "大连"){
      this.$http.get("./data/dalian_data.json").then(res => {
        this.list = res.data.list;
      });      
    }
    // var that = this;
    // 控制电梯导航的显示和隐藏
    // $(window).scroll(function(){
    //     if($("#index").attr("index")!=1) {
    //       return false;
    //     }
    //     if($(this).scrollTop() > $(".guess").eq(1).offset().top){
    //         that.show=true;
    //     }else{
    //         that.show=false;
    //     }
    // })

  }
};
</script>
<style scoped>
body {
  background: #F0EFED;
}
em,
i {
  font-style: normal;
}
header {
  display: flex;
  height: 50.5px;
  align-items: center;
  background-image: linear-gradient(135deg, #ffd000 0%, #ffbd00 100%);
}

header .toAddress {
  width: 75px;
  text-align: center;
  font-size: 14px;
  color: #222;
}
.toAddress .dropdown {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-left: 1px solid #000;
  border-bottom: 1px solid #000;
  transform: translateY(-3px) rotate(-45deg);
}

header .search {
  flex: 1;
}

header .search input {
  width: 100%;
  height: 32px;
  border-radius: 7px;
  outline: none;
  border: none;
  font-size: 14px;
  color: #ccc;
}

header .man-icon {
  width: 47px;
  height: 50.5px;
}

header .man-icon img {
  transform: scale(0.25) translate(-100px, -96px);
}

.banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 52px;
  padding: 0 15px;
  background: #000;
  color: #fff;
}
.banner img {
  width: 36px;
  height: 36px;
}
.banner_left{
  display: flex;
}
.banner_message {
  margin-left: 10px;
  display: flex;
  flex-direction: column;
  font-size: 13px;
}
.banner_right {
    width: 55px;
    height: 30px;
    background-image: linear-gradient(135deg, #FFD000 0%, #FFBD00 100%);
    border-radius: 7px;
    line-height: 30px;
    text-align: center;
    color: #000;
    font-size: 12px;
}
nav {
  height: 165px;
  background: #fff;
}

nav .navbar {
  display: flex;
  height: 165px;
  flex-wrap: wrap;
  align-content: center;
}

nav .navbar li {
  flex: 20%;
}

nav .navbar li:nth-child(-n + 5) {
  margin-bottom: 20px;
}

nav .navbar li a {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  font-size: 12px;
  color: #666;
}

nav .navbar li .item-icons {
  width: 40px;
  height: 41px;
  margin-bottom: 5px;
  background: url(../../data/img/navbar.png) -4px -4px no-repeat;
}

main {
  margin-top: 10px;
  padding: 0 10px 10px 10px;
  background: #fff;
}

main dt {
  height: 41px;
  line-height: 41px;
  border-bottom: 1px solid #ddd8ce;
  margin-bottom: 15px;
  color: #333;
}
main dd {
  border-bottom: 1px solid #ddd8ce;
}

main dd:nth-child(n + 1) {
  margin-top: 15px;
}

main dd a {
  display: block;
  margin-bottom: 10px;
}

main dd .item-commodity {
  display: flex;
}
main dd .commodity-pic {
  width: 90px;
  height: 90px;
}
main dd img {
  width: 100%;
}
main dd .description {
  flex: 1;
  margin-left: 15px;
  font-size: 12px;
  color: #666;
}
main .description section {
  overflow: hidden;
  margin-top: 16px;
}
main .description h5 {
  font-size: 15px;
  color: #333;
  font-weight: 400;
}
main .description p {
  height: 34px;
}
main .description .actual-price {
  color: #f60;
  font-size: 12px;
}
main .description .num-price {
  font-size: 18px;
}
main .description .actual-price,
main .description .market {
  float: left;
  height: 24px;
}
main .description .market {
  line-height: 29px;
  margin-left: 5px;
}
main .description .sold {
  float: right;
  height: 24px;
  line-height: 29px;
}
main .checkAll {
  padding: 0 5px;
  position: relative;
  height: 40px;
  line-height: 40px;
  border-bottom: 2px solid #ccc;
  cursor: pointer;
}
main .checkAll .left-check {
  float: left;
  color: #fe8c00;
}
main .checkAll::after {
  position: absolute;
  top: 50%;
  right: 10px;
  display: block;
  content: "";
  width: 0.6em;
  height: 0.6em;
  border-left: 2px solid #fe8c00;
  border-bottom: 2px solid #fe8c00;
  transform: translateY(-50%) scaleY(0.7) rotate(-135deg);
}

footer {
  box-sizing: border-box;
  height: 60px;
  padding: 15px 20px;
  font-size: 13px;
  background-color: #fff;
}
footer .footer-navbar {
  float: left;
}

footer .footer-location {
  float: right;
}

.footer-location a {
  color: #000;
}
footer .btn-login,
footer .btn-reg {
  display: inline-block;
  background-image: linear-gradient(135deg, #ffd000 0%, #ffbd00 100%);
  border-radius: 5px;
  font-size: 12px;
  color: #222222;
  width: 55px;
  height: 27px;
  font-family: PingFangSC-Medium;
  line-height: 27px;
  text-align: center;
}
.footer-location img {
  width: 12px;
  height: 13.7px;
  margin-top: -3px;
  vertical-align: middle;
}
.footer-location .city {
  color: #999999;
}
/* 电梯导航 */

.icon-elevator {
  position: fixed;
  right: 15px;
  bottom: 75px;
  width: 50px;
  height: 50px;
  background: url(../assets/images/icon_top1.png) no-repeat;
  background-size: 50px;
}

</style>